package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.CenterBean03;
import com.lwj.liwanjia.utils.RatingBar;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by 001 on 2017/9/10.
 */

public class PinJiaAdapter extends BaseAdapter {


    private Context mContext;
    private List<CenterBean03.DataBean> mList;

    public PinJiaAdapter(Context mContext, List<CenterBean03.DataBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_pin_jia, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        CenterBean03.DataBean bean = mList.get(position);
        holder.tvName.setText(bean.getUserNick());
        Glide.with(mContext).load(bean.getUserHeadImg()).error(R.mipmap.touxiang).into(holder.circlePhoto);//左边头像
        Glide.with(mContext).load(bean.getGoodsInfo().getImgUrl()).error(R.mipmap.tupian).into(holder.ivPhoto);//商品图片
        holder.tvTime01.setText(bean.getCommentTime());
        holder.rating.setStar((float) bean.getCommentGrade());
        holder.tvYongHuPinJia.setText(bean.getCommentContent());
        CenterBean03.DataBean.GoodsInfoBean goodsInfo = bean.getGoodsInfo();
        holder.tvNameDown.setText(goodsInfo.getCommodityName());
        holder.tvContent.setText(goodsInfo.getCommodityInfo());
        holder.tvMoney.setText("¥" + goodsInfo.getPrice());

        //用户追评
        if (!TextUtils.isEmpty(bean.getAddCommentContent())) {
            holder.rlZhuiping.setVisibility(View.VISIBLE);
            holder.zhuijiaContent.setText(bean.getAddCommentContent());
        } else {
            holder.rlZhuiping.setVisibility(View.GONE);
        }

        //商家回复
        if (!TextUtils.isEmpty(bean.getReplyInfo())) {
            holder.rlShangJiaHuiFu.setVisibility(View.VISIBLE);
            holder.tvShangJiaHuiFu.setText(bean.getReplyInfo());
            holder.tvHuifuTime.setText(bean.getReplyTime());
        } else {
            holder.rlShangJiaHuiFu.setVisibility(View.GONE);
        }
        return convertView;
    }

    static class ViewHolder {

        @BindView(R.id.circle_photo)
        CircleImageView circlePhoto;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_time01)
        TextView tvTime01;
        @BindView(R.id.rating)
        RatingBar rating;
        @BindView(R.id.tv_yongHuPinJia)
        TextView tvYongHuPinJia;
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;
        @BindView(R.id.tv_name_down)
        TextView tvNameDown;
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.rl_shangPin)
        RelativeLayout rlShangPin;
        @BindView(R.id.zhuijia_time)
        TextView zhuijiaTime;
        @BindView(R.id.zhuijia_content)
        TextView zhuijiaContent;
        @BindView(R.id.rl_zhuiping)
        RelativeLayout rlZhuiping;
        @BindView(R.id.tv1)
        TextView tv1;
        @BindView(R.id.tv_shangJiaHuiFu)
        TextView tvShangJiaHuiFu;
        @BindView(R.id.tv_huifu_time)
        TextView tvHuifuTime;
        @BindView(R.id.rl_shangJiaHuiFu)
        RelativeLayout rlShangJiaHuiFu;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
